{include file="public/layout" /}
<body style="overflow: auto; cursor: default; -moz-user-select: inherit;background-color:#F4F4F4;">
    <div id="append_parent"></div>
    <div id="ajaxwaitid"></div>
    <div id="geduan_div" class="h10"></div>
    <div id="page_div" class="page min-hg-c-66">
        <div class="flexigrid">
            <div class="mDiv">
                <div class="ftitle">
                    <div class="fbutton">
                        <a href="javascript:void(0);" onclick="addGoodsLabel();">
                            <div class="add" title="新增服务"><span><i class="layui-icon layui-icon-addition"></i>新增服务</span></div>
                        </a>
                    </div>
                </div>
            </div>
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                            <tr>
                                <th class="w200"> <div class="text-l10">商品服务</div> </th>
                                <th class="w100"> <div class="tc">图标</div> </th>
                                <th class=""> <div class="text-l10">描述</div> </th>
                                <th class="w120"> <div class="tc">操作</div> </th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="bDiv" style="height: auto;">
                <form id="postForm">
                    <input type="hidden" name="aid" value="{$aid}">
                    <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                        <table style="width: 100%;">
                            <tbody>
                                {empty name="goodsLabel"}
                                <tr>
                                    <td class="no-data" align="center" axis="col0" colspan="50">
                                        <div class="no_row">
                                            <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                        </div>
                                    </td>
                                </tr>
                                {else/}
                                {foreach name="goodsLabel" item="vo" key="k" }
                                <tr class="tr">
                                    <td>
                                        <div class="w200 text-l10">
                                            <input type="hidden" name="label_id[]" value="{$vo.label_id}">
                                            <input type="hidden" name="label_mark[]" value="{$vo.label_id}">
                                            <input type="text" name="label_title[]" id="labelTitle_{$vo.label_id}" value="{$vo.label_title}">
                                        </div>
                                    </td>
                                    <td>
                                        <div class="type-dan-pane w100 tc">
                                            <div class="images_upload images_upload_html">
                                                <a href="javascript:void(0);" id="labelClick_{$vo.label_id}" onclick="updateGoodsLabelPic({$vo.label_id});" class="img-upload no-float" title="点击上传">
                                                    <div class="y-line" id="labelPicYLine_{$vo.label_id}" {notempty name="$vo.label_pic"} style="display: none;" {/notempty}></div>
                                                    <div class="x-line" id="labelPicXLine_{$vo.label_id}" {notempty name="$vo.label_pic"} style="display: none;" {/notempty}></div>
                                                    <img src="{$vo.label_pic}" id="labelPicSrc_{$vo.label_id}" class="pic_con">
                                                </a>
                                                <a href="javascript:void(0)" onclick="clearGoodsLabelPic({$vo.label_id});" class="delect" title="删除"></a>
                                                <input type="hidden" id="labelPic_{$vo.label_id}" name="label_pic[]" value="{$vo.label_pic}">
                                            </div>
                                        </div>
                                    </td>
                                    <td align="left" style="width: 100%">
                                        <div class="tl text-l10" >
                                            <input type="text" name="label_intro[]" id="labelIntro_{$vo.label_id}" value="{$vo.label_intro}" style="width: 95%">
                                        </div>
                                    </td>
                                    <td class="operation">
                                        <div class="w120 tc">
                                            <a class="btn red" href="javascript:void(0);" data-id="{$vo.label_id}" onclick="delGoodsLabel(this);">删除</a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                                {/empty}
                            </tbody>
                        </table>
                        <div id='Template'></div>
                    </div>
                </form>
                <div class="iDiv" style="display: none;"></div>
            </div>
            {notempty name="goodsLabel"}
            <div class="tDiv">
                <div class="tDiv2">
                    <div class="fbutton">
                        <a href="javascript:void(0);" onclick="saveGoodsLabel(this);" class="layui-btn layui-btn-primary"><span class="">保存</span></a>
                    </div>
                </div>
                <div style="clear:both"></div>
            </div>
            {/notempty}
        </div>
    </div>

<script type="text/javascript">
    var currentID = 0;
    function updateGoodsLabelPic(labelID) {
        currentID = labelID;
        // 调用图片上传
        GetUploadify(1, '', 'allimg', 'updateGoodsLabelPicBack');
    }

    // 加载新图片
    function updateGoodsLabelPicBack(pic) {
        $('#labelPic_' + currentID).val(pic);
        $('#labelPicSrc_' + currentID).show().attr('src', pic);
        $('#labelPicYLine_' + currentID + ', #labelPicXLine_' + currentID).hide();
    }

    // 清除图片信息
    function clearGoodsLabelPic(labelID) {
        $('#labelPic_' + labelID).val('');
        $('#labelPicSrc_' + labelID).hide().attr('src', '');
        $('#labelPicYLine_' + labelID + ', #labelPicXLine_' + labelID).show();
    }

    var maxGoodsLabelID = {$maxGoodsLabelID};
    // 新增商品标签
    function addGoodsLabel() {
        // 最大商品标签ID自增
        maxGoodsLabelID++;
        // html代码
        var addLabel = [];
        addLabel += [
            '<tr class="tr">'+
                '<td>'+
                    '<div class="w200 text-l10">'+
                        '<input type="hidden" name="label_id[]" value="0">'+
                        '<input type="hidden" name="label_mark[]" value="'+maxGoodsLabelID+'">'+
                        '<input type="text" name="label_title[]" id="labelTitle_'+maxGoodsLabelID+'" placeholder="请输入服务名称">'+
                    '</div>'+
                '</td>'+
                '<td>'+
                    '<div class="type-dan-pane w100 tc">'+
                        '<div class="images_upload images_upload_html">'+
                            '<a href="javascript:void(0);" id="labelClick_'+maxGoodsLabelID+'" onclick="updateGoodsLabelPic('+maxGoodsLabelID+');" class="img-upload no-float" title="点击上传">'+
                                '<div class="y-line" id="labelPicYLine_'+maxGoodsLabelID+'"></div>'+
                                '<div class="x-line" id="labelPicXLine_'+maxGoodsLabelID+'"></div>'+
                                '<img src="" id="labelPicSrc_'+maxGoodsLabelID+'" class="pic_con" style="display: none;">'+
                            '</a>'+
                            '<a href="javascript:void(0)" onclick="updateGoodsLabelPicClear('+maxGoodsLabelID+');" class="delect" title="删除"></a>'+
                            '<input type="hidden" id="labelPic_'+maxGoodsLabelID+'" name="label_pic[]">'+
                        '</div>'+
                    '</div>'+
                '</td>'+
                '<td align="left" style="width: 100%">'+
                    '<div class="tl text-l10">'+
                        '<input type="text" name="label_intro[]" id="labelIntro_'+maxGoodsLabelID+'" placeholder="请输入服务描述" style="width: 95%">'+
                    '</div>'+
                '</td>'+
                '<td class="operation">'+
                    '<div class="w120 tc">'+
                        '<a class="btn red" href="javascript:void(0);" data-id="0" onclick="delGoodsLabel(this);">删除</a>'+
                    '</div>'+
                '</td>'+
            '</tr>'
        ];
        $('.no-data').hide();
        $('#Template').append(addLabel);
    }

    // 保存商品标签
    function saveGoodsLabel() {
        layer_loading('正在处理');
        $.ajax({
            type: 'post',
            url : "{:url('ShopProduct/goods_label_save')}",
            data: $('#postForm').serialize(),
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    parent.setGoodsLabelCallBack(res);
                    // showSuccessMsg(res.msg, 1500, function() {
                    //     window.location.reload();
                    // });
                } else {
                    showErrorAlert(res.msg, 0, function() {
                        layer.closeAll();
                        if (res.data.id) $(res.data.id).focus();
                    });
                }
            },
            error: function(e) {
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }

    // 删除商品标签
    function delGoodsLabel(obj) {
        $(obj).parent().parent().parent().remove();
        // var labelID = $(obj).data('id');
        // if (0 === parseInt(labelID)) {
        //     $(obj).parent().parent().parent().remove();
        // } else {
        //     showConfirm('确认执行删除？不可恢复！', {}, function() {
        //         layer_loading('正在处理');
        //         $.ajax({
        //             type: 'post',
        //             url : "{:url('ShopProduct/goods_label_del')}",
        //             data: {labelID: $(obj).data('id'), _ajax: 1},
        //             dataType: 'json',
        //             success: function(res) {
        //                 layer.closeAll();
        //                 if (1 === parseInt(res.code)) {
        //                     showSuccessMsg(res.msg);
        //                     $(obj).parent().parent().parent().remove();
        //                 } else {
        //                     showErrorAlert(res.msg);
        //                 }
        //             },
        //             error: function(e) {
        //                 layer.closeAll();
        //                 showErrorAlert(e.responseText);
        //             }
        //         });
        //     });
        // }
    }
</script>
{include file="public/footer" /}